//////////////////////////////////////////////////////////////////////////////
//																			//
//  Filename:    RealmOfRichesGuts.h										//
//  Developer:   Ryan Sauls													//
//  Create date: 1/12/2005													//
//																			//
//////////////////////////////////////////////////////////////////////////////
//																			//
//  Description: This is the class declaration for the slot gut of the		//
//               Australian Slot machine called Realm Of Riches.			//
//																			//
//////////////////////////////////////////////////////////////////////////////
//        Copyright (c) 2006 - Realtime Gaming.  All rights reserved.		//
//////////////////////////////////////////////////////////////////////////////
#ifndef __REALM_OF_RICHES_GUTS_H__
#define __REALM_OF_RICHES_GUTS_H__

#pragma once


#include "slotguts.h"
#include "getrand.h"

class RealmOfRichesGuts :
	public SlotGuts
{
        typedef SlotGuts super;
public:
	enum GutsRange
	{
		MIN = 3500,
		MAX = 3999
	};

private:

	#include "RealmOfRichesCommon.h"
	
	// Helpful lookup arrays.
	static SpinResult m_aLineWinSpinResults[NUM_VALID_ICONS][6];

	static SpinResult m_aScatterWinSpinResults[6];
	
	// Inline functions to use with the arrays that also do
	// bounds checking.
	static SpinResult lookupLineWinSpinResult( uint8 nIconType, uint8 nCount )
	{
		if ( nIconType < NUM_VALID_ICONS && nCount < 6 )
		{
			return m_aLineWinSpinResults[ nIconType ][ nCount ];
		}

		ASSERT( false );
		return EVT_INVALID;
	}

	static SpinResult lookupScatterWinSpinResult( uint8 nCount )
	{
		if ( nCount < 6 )
		{
			return m_aScatterWinSpinResults[ nCount ];
		}

		ASSERT( false );
		return EVT_INVALID;
	}

	static uint8 lookupScatterIconCount( SpinResult result )
	{
		switch (result)
		{
		case EVT_SCATTER_NEAR_MISS:
			return 1;
		case EVT_TWO_SHIELD:
			return 2;
		case EVT_THREE_SHIELD:
			return 3;
		case EVT_FOUR_SHIELD:
			return 4;
		case EVT_FIVE_SHIELD:
			return 5;
		default:
			return 0;
		};
	}

public:
	RealmOfRichesGuts(void);
	virtual ~RealmOfRichesGuts(void);

	void classifyStops( SpinLine* spinLine, uint8* stops, uint8 bet, uint8 line, 
									uint8& rtnResult, uint8& multiplier );

	void classifyScatters( SlotSpin* spin );

	bool8 isValidGuts();

	void getGameModeMultiplierAndNoteId (uint8& nGameModeMultiplier, uint8& nNoteId );

    const SlotIcon* getIcon( uint8 gamemodeID, uint8 reelID, uint8 position ) const;

    bool8 load(Info *info);

	void allocateSubGameData();

protected:
    typedef std::map< const SlotIcon*, SlotIcon*> SlotIconSubstitutionMap;

	bool8	m_bAllowCrownSubstitutions;

    SlotIconSubstitutionMap m_mapSubstitutionIcons;

    bool8 allocateCrownSubstitutionIcons();

    void  deallocateCrownSubstitutionIcons();

    void  addSubstitutionIcon( const SlotIcon* current );
    
    SpinResult getCrownLineWinResult( uint8* stops ) const;
    
    SpinResult getLineWinResultWithPossibleSubstitution(uint8* stops, uint8 testIcon, 
        bool& bSubstitution ) const;
    
    bool doesCrownLineWinPayMore( SpinResult srCrown, SpinResult srOther ) const;
    
    void tryForJackpot( SlotSpin* spin );
    
    SpinResult getScatterWinResult( SlotSpin* spin, int32& scatterPositions ) const;
    
    void evaluateScatterWin( SlotSpin* spin, SpinResult srScatterResult, int32 scatterPositions );
    
    void evaluateFeatureTrigger( SlotSpin* spin, SpinResult srScatterResult, int32 scatterPositions);
    
    void  resetReelHoldStops();
    void  setReelHoldStop( uint8 nReel , int32 stop);
    int32 getReelHoldStop( uint8 nReel );
    
    void  resetFreeSpinCrownSubstitutions();
    void  setFreeSpinCrownSubstitution( uint8 nReel , int32 stop);
    int32 getFreeSpinCrownSubstitution( uint8 nReel ) const;

    void preSpinClassifyResults( SlotSpin* spin );
	virtual void Debug_SetLoserStops( uint8* pStops );
};

#endif //__REALM_OF_RICHES_GUTS_H__